Subject: Re: Best way to manage memory in a text editor
From: [email-masked] (Colin Plumb)
Date: Mon, 6 Dec 93 22:25:18 GMT
Newsgroups: comp.programming

In article <[email-masked]>,
Alex Matulich <[email-masked]> wrote:
>
>Hi.  I'm the author of a timed script player for titling foreign videos.
>My users have been clamoring for a built-in editor to my software, so I
>began writing a simple text editor to do the job.
>
>I soon discovered that I had several memory management options open to me,
>and I was uncertain which was best.  Certainly some were more difficult to
>implement than others. 

Get a book titled _The Craft of Text Editing: Emacs for the modern world_.
It is the definitive reference for all sorts of algorithms.  It's also
highly enlightening just to read.  By Craig Finseth.  MIT PRess, *I think*,
but I might be wrong.

In any case, the best general algorithm is the buffer gap.  That is,
you have a buffer of a given size, with all the text smashed up against
the beginning and end of the buffer, with a gap where the cursor is.
(Actually, don't move the gap until you type a character.)

If the gap "fills in" and becomes zero size, you can either make the
buffer larger, or go to a paged buffer gap, where you keep a list of
fixed-size pages, and split and merge when they become empty and full.

But get Finseth's book.  It addresses *all sorts* of issues in text editor
design.
-- 
	-Colin